$(function() {

	// 单独的文件上传插件集成(可进行多文件上传)
	// var settings = {
	// url : Globals.ctx + "attachment/upload",
	// method : "POST",
	// allowedTypes : "jpg,png,gif,doc,pdf,zip",
	// fileName : "file",
	// multiple : true,
	// onSuccess : function(files, data, xhr) {
	// if (data.retcode == 0) {
	// $("#status").html("<font color='red'>上传失败</font>");
	// } else {
	// $("#status").html("<font color='green'>上传成功</font>");
	// }
	// },
	// onError : function(files, status, errMsg) {
	// $("#status").html("<font color='red'>上传失败</font>");
	// }
	// }
	// $("#mulitplefileuploader").uploadFile(settings);
	// kindeditor编辑器上传设置
	var editor;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="description"]', {
			allowImageUpload : true,
			allowImageRemote : false,
			allowFileManager : true,
			imgPath : "/upload/image/",
			filePostName : "imgFile",
			showRemote : false,
			uploadJson : Globals.ctx + "attachment/upload",
			items : [ 'undo', 'redo', '|', 'preview', 'print', '|',
					'justifyleft', 'justifycenter', 'justifyright',
					'justifyfull', 'insertorderedlist', 'insertunorderedlist',
					'|', 'formatblock', 'fontname', 'fontsize', '|',
					'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
					'strikethrough', 'lineheight', '|', 'image', 'insertfile',
					'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
					'link', 'unlink' ]
		});
	});
	// summer note 富文本编辑器集成包含文件上传
	// $('.summernote').summernote(
	// {
	// height : "150px",
	// width : "300px",
	// lang : 'zh-CN',
	// focus : true,
	// callbacks : {},
	// // onImageUpload : function(files, editor, welEditable) {
	// // console.log('image upload:', files, editor, $editable);
	// // sendFile(files[0], editor, welEditable);
	// // },
	// onImageUploadError : function(data) {
	//
	// },
	// toolbar : [ [ 'font', [ 'bold', 'underline', 'clear' ] ],
	// [ 'fontname', [ 'fontname' ] ],
	// [ 'color', [ 'color' ] ],
	// [ 'para', [ 'ul', 'ol', 'paragraph' ] ],
	// [ 'table', [ 'table' ] ],
	// [ 'insert', [ 'link', 'picture', ] ],
	// [ 'view', [ 'fullscreen' ] ] ],
	// });
	var id = "";
	var userApp = new Vue({
		el : '#userApp',
		data : {
			items : [],
			editUser : []
		},
		methods : {
			addBtn : function(event) {
				event.preventDefault();
				$('#addDiv').modal('show');
			},
			editBtn : function(event) {
				var checkBoxArray = $("input:checked");
				id = $("input:checked").val();
				if (checkBoxArray.length > 1) {
					failureTip("只能选择一条记录");
					return;
				}
				if (checkBoxArray.length < 1) {
					failureTip("请选择一条记录操作");
					return;
				}
				$.post(Globals.ctx + "user/selectUserById", {
					id : id
				}, function(data, textStatus, req) {
					userApp.$data.editUser = data.retdata;
				}, 'json');
				event.preventDefault();
				$('#editDiv').modal('show');
			},
			deleteBtn : function(event) {
				var checkBoxArray = $("input:checked");
				id = $("input:checked").val();
				if (checkBoxArray.length > 1) {
					failureTip("只能选择一条记录");
					return;
				}
				if (checkBoxArray.length < 1) {
					failureTip("请选择一条记录操作");
					return;
				}
				event.preventDefault();
				$('#delDiv').modal('show');
			},
			delRecord : function() {
				$.post(Globals.ctx + "user/delete", {
					id : id
				}, function(data, textStatus, req) {
					if (data.retcode == 1) {
						successTip(data.retmsg);
					} else {
						failureTip(data.retmsg);
					}
					location.href = Globals.ctx + "user/userInfo";
				}, 'json')
			}
		}
	});
	$.post(Globals.ctx + "user/userList", {}, function(data, textStatus, req) {
		userApp.$data.items = data.retdata.content;
	}, 'json');
});
/**
 * sumenote 文件上传方法
 * 
 * @param file
 * @param editor
 * @param welEditable
 */
function sendFile(file, editor, welEditable) {
	data = new FormData();
	data.append("imgFile", file);
	$.ajax({
		data : data,
		type : "POST",
		url : Globals.ctx + "attachment/uploadImage",
		cache : false,
		contentType : false,
		processData : false,
		success : function(data) {
			alert("dfsggrtt");
			editor.insertImage(welEditable, data.url);
		}
	});
}